var Adv_skd=require("./Adv_skd")
var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("AssetsMap"),
    c = e("BundleNames"),
    l = e("GridLayerListView"),
    d = e("GridListView"),
    u = e("CCPoolManager"),
    p = e("GlobalParam"),
    h = e("Util"),
    f = e("GameData"),
    _ = e("SkinLevelData"),
    y = e("StartModuleViewMediator"),
    m = e("ShopSkinViewMediator"),
    g = e("CustomerAnimal"),
    v = e("DecorateItem"),
    w = e("MapScrollview"),
    b = e("ShopSnakeItem"),
    C = cc._decorator,
    k = C.ccclass,
    N = C.property,
    B = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.bgNode = null),
                (t.snakeScrollview = null),
                (t.snakeItem = null),
                (t.themeItem = null),
                (t.decorateBtn = null),
                (t.decorateContent = null),
                (t.decorateListView = null),
                (t.decorateItem = null),
                (t.snakeName = null),
                (t.snakeLevelTypeNode = null),
                (t.upgradeInfo = null),
                (t.upgradeBtn = null),
                (t.gooutBtn = null),
                (t.leftBtn = null),
                (t.rightBtn = null),
                (t.isOpenDecorate = !0),
                (t.currentThemeIndex = -1),
                (t.decorateDataCache = new Map()),
                (t.decorateOtherInfoCache = new Map()),
                t
            );
        }
        return (
            a(t, e),
            (t.prototype.onLoad = function () {
                if (
                    ((this.isCache = !1),
                    this.decorateListView
                        .getComponent(l.default)
                        .registerEvent(d.GridListViewEvent.DELEGATE, this.updateDecorateItem, this),
                    this.decorateListView
                        .getComponent(l.default)
                        .registerEvent(d.GridListViewEvent.DELEGATE_UPDATE, this.allUpdateDecorateItem, this),
                    this.decorateItem)
                ) {
                    var e = cc.instantiate(this.decorateItem);
                    (e.active = !0), u.default.instance().initNode("decorate_item", e, 20);
                }
                this.snakeScrollview.init(), this.snakeScrollview.registerSkipEvent(this.snakeItemSkip, this);
            }),
            (t.prototype.onEnable = function () {
                Adv_skd.default.instance.hideAllAdv();
                console.log("激活")
                cc.SDK.showGetUICoinBox(
                    function (e) {
                        var t = f.default.instance.getPlayerCoin();
                        f.default.instance.setPlayerCoin(t + e);
                    },
                    function () { },
                    cc.SDK.gameID
                );
            }),
            (t.prototype.onClickClose = function () {
                Adv_skd.default.instance.hideAllAdv();

                Adv_skd.default.instance.showGridAdLeftOne();
                Adv_skd.default.instance.showGridAdRightOne();
                Adv_skd.default.instance.showInterstitialAd();

                game.AudioManager.playBtnEffect(), this.closeView(!0);
            }),
            (t.prototype.onResetView = function () {
                e.prototype.onResetView.call(this);
                var t = ad.curr_platform === window.ad.Platform.TOU_TIAO;
                game.log("T=> 进入商店"),
                    t && window.tt.reportAnalytics("PiFU", {}),
                    this.dataInit(),
                    this.themeItem.init(),
                    this.themeItem.registerSkipEvent(this.themeSkip, this),
                    this.themeItem.renderItem(),
                    this.snakeScrollview.clearData(),
                    (this.currentThemeIndex = 1),
                    this.renderSnakeList(1),
                    (this.decorateListView.totalCount = p.default.DecorateData.length),
                    ad.curr_platform === window.ad.Platform.VIVO && ad.adInterface.hideGamePortal(!1);
            }),
            (t.prototype.dataInit = function () {
                var e = this;
                p.default.DecorateData.forEach(function (t) {
                    e.decorateDataCache.set(t.index, t);
                    var o = {
                        isUnlock: "true" == h.default.getItem("dressItemLock" + t.index, "false"),
                        lockNum: Number(h.default.getItem("dressItemLockNum" + t.index, "0"))
                    };
                    e.decorateOtherInfoCache.set(t.index, o);
                });
            }),
            (t.prototype.registerMediator = function () {
                e.prototype.registerMediator.call(this), game.appFacade.registerMediator(new m.default(this));
            }),
            (t.prototype.removeMediator = function () {
                e.prototype.removeMediator.call(this), game.appFacade.removeMediator(m.default.NAME);
            }),
            (t.prototype.addEvent = function () {
                e.prototype.addEvent.call(this),
                    this.decorateBtn.on(game.EngineEventType.NodeEvent.click, this.clickDecorateBtn, this),
                    this.upgradeBtn.on(game.EngineEventType.NodeEvent.click, this.clickUpgrade, this),
                    this.gooutBtn.on(game.EngineEventType.NodeEvent.click, this.clickGoout, this),
                    this.leftBtn.on(game.EngineEventType.NodeEvent.click, this.clickLeft, this),
                    this.rightBtn.on(game.EngineEventType.NodeEvent.click, this.clickRight, this);
            }),
            (t.prototype.removeEvent = function () {
                e.prototype.removeEvent.call(this),
                    this.decorateBtn.off(game.EngineEventType.NodeEvent.click, this.clickDecorateBtn, this),
                    this.upgradeBtn.off(game.EngineEventType.NodeEvent.click, this.clickUpgrade, this),
                    this.gooutBtn.off(game.EngineEventType.NodeEvent.click, this.clickGoout, this),
                    this.leftBtn.off(game.EngineEventType.NodeEvent.click, this.clickLeft, this),
                    this.rightBtn.off(game.EngineEventType.NodeEvent.click, this.clickRight, this);
            }),
            (t.prototype.renderSnakeList = function (e, t) {
                void 0 === t && (t = !0), this.snakeScrollview.clearData(t);
                for (var o = _.SkinLevelData.instance.getSkinLevelByTheme(e), n = 0; n < o.length; n++) {
                    var i = cc.instantiate(this.snakeItem);
                    (i.active = !0), this.snakeScrollview.addPage(i);
                    var a = i.getComponent(b.default);
                    a.initConfig(o[n]),
                        n === this.snakeScrollview.getCurrentIndex() &&
                            (a.snakeTwist.startAction(), this.renderSnakeNameInfo(a.config));
                }
                this.renderBtn();
            }),
            (t.prototype.clickLeft = function () {
                this.snakeScrollview.left();
            }),
            (t.prototype.clickRight = function () {
                this.snakeScrollview.right();
            }),
            (t.prototype.renderBtn = function () {
                this.snakeScrollview.getCurrentIndex() <= 0 ? (this.leftBtn.active = !1) : (this.leftBtn.active = !0),
                    this.snakeScrollview.getCurrentIndex() >= this.snakeScrollview.itemCount() - 1
                        ? (this.rightBtn.active = !1)
                        : (this.rightBtn.active = !0);
            }),
            (t.prototype.clickDecorateBtn = function () {
                game.AudioManager.playBtnEffect(),
                    cc.Tween.stopAllByTarget(this.decorateContent),
                    (this.isOpenDecorate = !this.isOpenDecorate),
                    this.isOpenDecorate
                        ? ((this.decorateBtn.getChildByName("jian").angle = 0),
                          cc.tween(this.decorateContent).to(0.2, {y: 0}).start())
                        : ((this.decorateBtn.getChildByName("jian").angle = 180),
                          cc.tween(this.decorateContent).to(0.2, {y: -577}).start());
            }),
            (t.prototype.updateDecorateItem = function (e, t, o) {
                var n = o.getComponent(v.default),
                    i = this.decorateDataCache.get(t + 1),
                    a = this.decorateOtherInfoCache.get(t + 1),
                    r = this.snakeScrollview.getCurrentIndexItem().getComponent(b.default).decoIndex === i.index;
                n.review(i, a, r);
            }),
            (t.prototype.allUpdateDecorateItem = function (e) {
                var t = e.getComponent(v.default),
                    o = t.config,
                    n = this.decorateOtherInfoCache.get(o.index),
                    i = this.snakeScrollview.getCurrentIndexItem().getComponent(b.default).decoIndex === o.index;
                t.review(o, n, i);
            }),
            (t.prototype.snakeItemSkip = function (e, t) {
                e.getComponent(b.default).snakeTwist.stopAction();
                var o = t.getComponent(b.default);
                o.snakeTwist.startAction(),
                    this.renderSnakeNameInfo(o.config),
                    this.decorateListView.updateItems(),
                    this.renderBtn();
            }),
            (t.prototype.themeSkip = function (e) {
                this.renderSnakeList(e + 1);
                var t = this.bgNode.getChildByName("bg_" + this.currentThemeIndex),
                    o = this.bgNode.getChildByName("bg_" + (e + 1));
                (this.currentThemeIndex = e + 1),
                    (t.zIndex = 1),
                    (o.zIndex = 2),
                    cc
                        .tween(o)
                        .to(0.3, {opacity: 255})
                        .call(function () {
                            t.opacity = 0;
                        })
                        .start();
            }),
            (t.prototype.renderSnakeNameInfo = function (e) {
                this.snakeName.string = e.chinese;
                var t = this.snakeLevelTypeNode.getChildByName("level_1"),
                    o = this.snakeLevelTypeNode.getChildByName("level_2"),
                    n = this.snakeLevelTypeNode.getChildByName("level_3");
                (t.active = "普通" === e.level_type[0]),
                    (o.active = "传说" === e.level_type[0]),
                    (n.active = "史诗" === e.level_type[0]);
                var i = _.SkinLevelData.instance.skinList[e.index];
                this.upgradeBtn.active = i.level < i.upgrade.length - 1;
                var a = this.upgradeInfo.getChildByName("upgrade_ass");
                a.active = i.level < i.upgrade.length - 1;
                var r = a.getChildByName("num_pro").getComponent(cc.Label),
                    l = i.isLock ? "升级" : "合成";
                (this.upgradeBtn.getChildByName("tip").getComponent(cc.Label).string = l),
                    (r.string = f.default.instance.getPlayerCoin() + "/" + i.coin[i.level]);
                var d = this.upgradeInfo.getChildByName("goout_btn"),
                    u = this.upgradeInfo.getChildByName("gouting");
                if (
                    (cc.Tween.stopAllByTarget(u),
                    cc.Tween.stopAllByTarget(d),
                    (u.opacity = 255),
                    (d.opacity = 255),
                    i.isLock)
                ) {
                    var p = f.default.instance.UserSkin;
                    (d.active = p !== i.index),
                        (u.active = p === i.index),
                        d.active && ((d.opacity = 0), cc.tween(d).to(0.3, {opacity: 255}).start()),
                        u.active && ((u.opacity = 0), cc.tween(u).to(0.3, {opacity: 255}).start());
                } else
                    u.active &&
                        cc
                            .tween(u)
                            .to(0.3, {opacity: 0})
                            .call(function () {
                                u.active = !1;
                            })
                            .start(),
                        d.active &&
                            cc
                                .tween(d)
                                .to(0.3, {opacity: 0})
                                .call(function () {
                                    d.active = !1;
                                })
                                .start();
                (this.upgradeInfo.getChildByName("snake_length").getComponent(cc.Label).string =
                    i.initlength[i.level].toString()),
                    (this.upgradeInfo.getChildByName("eat_range").getComponent(cc.Label).string =
                        i.eatSize[i.level].toString()),
                    (this.upgradeInfo.getChildByName("level").getComponent(cc.Label).string = (i.level + 1).toString()),
                    (a.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = h.default.getSpriteFrame(
                        c.default.Popup,
                        s.default.PopupMap.ShopSkinView.preAssets.textures.assetsList["fragment_icon_" + i.name]
                    )),
                    (a.getChildByName("icon_num").getComponent(cc.Label).string =
                        i.fragments + "/" + i.upgrade[i.level]);
            }),
            (t.prototype.clickUpgrade = function () {
                game.AudioManager.playBtnEffect();
                var e = this.snakeScrollview.getCurrentIndexItem().getComponent(b.default).config;
                if (e.isLock) {
                    if (((t = e.coin[e.level]), f.default.instance.getPlayerCoin() < t))
                        return game.UIManager.instance.showToast("钻石不足");
                    if (((o = e.upgrade[e.level]), e.fragments < o))
                        return game.UIManager.instance.showToast("碎片不足");
                    _.SkinLevelData.instance.upgrade_level(e);
                } else {
                    var t = e.coin[e.level];
                    if (f.default.instance.getPlayerCoin() < t) return game.UIManager.instance.showToast("钻石不足");
                    var o = e.upgrade[e.level];
                    if (e.fragments < o) return game.UIManager.instance.showToast("碎片不足");
                    _.SkinLevelData.instance.upgrade_lock(e);
                }
                this.renderSnakeList(this.currentThemeIndex, !1), this.themeItem.renderItem();
            }),
            (t.prototype.clickGoout = function () {
                game.AudioManager.playBtnEffect();
                var e = this.snakeScrollview.getCurrentIndexItem().getComponent(b.default).config;
                e.isLock
                    ? (f.default.instance.setUserSkin(e.index),
                      game.UIManager.instance.showToast("出战成功"),
                      this.renderSnakeNameInfo(e),
                      game.appFacade.sendNotification(y.default.CHANGE_SKIN))
                    : game.UIManager.instance.showToast("暂未合成");
            }),
            (t.prototype.skikpEgg = function () {
                game.PopupManager.instance.showPopView(s.default.PopupMap.EggView, null, !0, !0),
                    e.prototype.closeView.call(this, !0);
            }),
            (t.prototype.closeView = function (t) {
                void 0 === t && (t = !0),
                    e.prototype.closeView.call(this, t),
                    ad.curr_platform === window.ad.Platform.VIVO && ad.adInterface.showGamePortal();
            }),
            r([N(cc.Node)], t.prototype, "bgNode", void 0),
            r([N(w.default)], t.prototype, "snakeScrollview", void 0),
            r([N(cc.Node)], t.prototype, "snakeItem", void 0),
            r([N(g.default)], t.prototype, "themeItem", void 0),
            r([N(cc.Node)], t.prototype, "decorateBtn", void 0),
            r([N(cc.Node)], t.prototype, "decorateContent", void 0),
            r([N(l.default)], t.prototype, "decorateListView", void 0),
            r([N(cc.Node)], t.prototype, "decorateItem", void 0),
            r([N(cc.Label)], t.prototype, "snakeName", void 0),
            r([N(cc.Node)], t.prototype, "snakeLevelTypeNode", void 0),
            r([N(cc.Node)], t.prototype, "upgradeInfo", void 0),
            r([N(cc.Node)], t.prototype, "upgradeBtn", void 0),
            r([N(cc.Node)], t.prototype, "gooutBtn", void 0),
            r([N(cc.Node)], t.prototype, "leftBtn", void 0),
            r([N(cc.Node)], t.prototype, "rightBtn", void 0),
            r([k], t)
        );
    })(game.BasePopView);
i.default = B;
